package com.yxhl.zoume.core.car.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.yxhl.protobuf.MpvValuationRules;
import com.yxhl.protobuf.OrderBizType;
import com.yxhl.zoume.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Author：zhongshan   
 * Date：2016/12/15 18:10      
 * Description：计价规则填充
 */
public class CarPricingRulesFillFragment extends Fragment {

    @BindView(R.id.tv_vehicle_type_desc)
    TextView mVehicleTypeDescTv;
    @BindView(R.id.tv_vehicle_type)
    TextView mVehicleTypeTv;
    @BindView(R.id.tv_base_fee)
    TextView mBaseFeeTv;
    @BindView(R.id.tv_base_fee_desc)
    TextView mBaseFeeDescTv;
    @BindView(R.id.tv_time_fee)
    TextView mTimeFeeDescTv;
    @BindView(R.id.tv_mileage_fee)
    TextView mMileageFeeDescTv;
    @BindView(R.id.iv_vehicle)
    ImageView vehicleIv;
    private Unbinder unbinder;

    private static final String ARGUMENT_KEY_MPV_VALUATION_RULES = "argument_key_mpv_valuation_rules";
    private MpvValuationRules mpvValuationRules;
    String basicFeeStr;
    String perKmPriceStr;
    private String perMinPriceStr;

    public static CarPricingRulesFillFragment newInstance(MpvValuationRules mpvValuationRules) {
        CarPricingRulesFillFragment fragment = new CarPricingRulesFillFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(ARGUMENT_KEY_MPV_VALUATION_RULES, mpvValuationRules);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_car_pricing_rules_fill, container, false);
        unbinder = ButterKnife.bind(this, inflate);
        return inflate;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        parseParams();
        initView();
    }

    private void initView() {

        int type = mpvValuationRules.getType();
        String basicFee = mpvValuationRules.getBasicFee();
        String perKmPrice = mpvValuationRules.getPerKmPrice();
        String perMinPrice = mpvValuationRules.getPerMinPrice();

        switch (type) {
            //单程
            case OrderBizType.SPECIAL_BUS_WAY_VALUE:
                basicFeeStr = basicFee + "    起步费";
                perKmPriceStr = perKmPrice + "    里程费";
                perMinPriceStr = perMinPrice + "    时长费";
                break;
            //分时
            case OrderBizType.SPECIAL_BUS_TIME_VALUE:
                basicFeeStr = basicFee + "    套餐费";
                perKmPriceStr = perKmPrice + "    超里程费";
                perMinPriceStr = perMinPrice + "    超时长费";
                break;
        }

        mBaseFeeTv.setText(basicFeeStr);
        mTimeFeeDescTv.setText(perMinPriceStr);
        mMileageFeeDescTv.setText(perKmPriceStr);
        mBaseFeeDescTv.setText(mpvValuationRules.getFeeDesc());
        mVehicleTypeTv.setText(mpvValuationRules.getModelName());
        mVehicleTypeDescTv.setText(mpvValuationRules.getMpvDesc());
        Picasso.with(getActivity())
                .load(mpvValuationRules.getPriceImgUrl())
                .into(vehicleIv);

    }

    private void parseParams() {
        Bundle arguments = getArguments();
        if (arguments != null) {
            mpvValuationRules = (MpvValuationRules) arguments.getSerializable(ARGUMENT_KEY_MPV_VALUATION_RULES);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (unbinder != null)
            unbinder.unbind();
    }
}
